#include "genericdialog.h"
#include "ui_genericdialog.h"
#include <QDebug>

GenericDialog::GenericDialog(QWidget *parent):QDialog(parent),ui(new Ui::GenericDialog),saveBtnClick(false),
    noSaveBtnClick(false),
    cancelBtnClick(false),
    closeBtbClick(false)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->raise();
    this->activateWindow();
    initial(); // 初始化按钮状态
}

GenericDialog::~GenericDialog()
{
    delete ui;
}
void GenericDialog::initial()
{
    saveBtnClick = false;
    noSaveBtnClick= false;
    cancelBtnClick = false;
    closeBtbClick=false;
}

void GenericDialog::on_closeBtn_clicked()
{
    closeBtbClick = true;
    this->reject();
}

void GenericDialog::on_saveBtn_clicked()
{
    saveBtnClick = true;
    this->reject();
}

void GenericDialog::on_noSaveBtn_clicked()
{
    noSaveBtnClick = true;
    this->reject();
}

void GenericDialog::on_cancelBtn_clicked()
{
    cancelBtnClick = true;
    this->reject();
}


GenericDialog &GenericDialog::getInstance()
{
    static GenericDialog instance;
    return instance;
}

GenericDialog* GenericDialog::showDialog()
{
    initial();
    this->exec();
    return this; // 支持链式调用
}

GenericDialog *GenericDialog::setWinTitle(const QString &text)
{
    ui->winTitle->setText(text.isEmpty()?"HanL的记事本":text);
    return this;
}

GenericDialog* GenericDialog::setWinMessage(const QString &text)
{
    ui->messageText->setText(text.isEmpty()?"当前窗口提示内容为空":text);
    return this;
}

GenericDialog *GenericDialog::setWinType(DialogType type)
{
    if(type==DialogType::TipDialog)
    {
        ui->dialogIcon->setPixmap(QPixmap(":/image/tipsWin.png").scaled(ui->dialogIcon->size()));
        ui->saveBtn->hide();
        ui->noSaveBtn->setText("确认");
        ui->noSaveBtn->setDefault(true);
    }else if(type==DialogType::ConfirmDialog)
    {
        ui->dialogIcon->setPixmap(QPixmap(":/image/rightWin.png").scaled(ui->dialogIcon->size()));
        ui->saveBtn->setDefault(true);
         ui->noSaveBtn->setText("不保存");
        ui->saveBtn->show();
    }else if(type==DialogType::WarmingDialog)
    {
        ui->dialogIcon->setPixmap(QPixmap(":/image/warmingWin.png").scaled(ui->dialogIcon->size()));
         ui->saveBtn->show();
    }
    return this;
}

bool GenericDialog::getSaveBtnClick()
{
    return saveBtnClick;
}

bool GenericDialog::getNoSaveBtnClick()
{
    return noSaveBtnClick;
}

bool GenericDialog::getCancelBtnClick()
{
    return cancelBtnClick;
}

bool GenericDialog::getCloseBtnClick()
{
    return closeBtbClick;
}




